<form class="layui-form seller-form" action="">
    <div class="layui-tab">
        <ul class="layui-tab-title">
            <li class="layui-this"><a href="{:url('tranForceButton')}">卡强制消费详情</a></li>
            <li><a href="{:url('tranForceTotal')}" >卡强制消费统计(实时)</a></li>
            <li><a href="{:url('tranForceKey')}">预扣>0,实际=0</a></li>
            <li><a href="{:url('tranForceDec')}">AMZ*Amazon Payments拒付统计</a></li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <div class="layui-inline" style="padding-left: 5px;">
                    <input type="text" name="user_name" lay-verify="title" placeholder="User Name" autocomplete="off"
                           class="layui-input">
                </div>
                <div class="layui-inline" style="padding-left: 5px;">
                    <input type="text" name="card_num" lay-verify="title" placeholder="Card Num" autocomplete="off"
                           class="layui-input">
                </div>
                <div class="layui-inline" style="padding-left: 5px;">
                    <input type="text" name="shopping" lay-verify="title" placeholder="Shopping" autocomplete="off"
                           class="layui-input">
                </div>
                <div class="layui-inline" style="padding-left: 5px;">
                    <input type="text" name="datetime" id="datetime" placeholder="Start Time _ End Time" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-inline">
                    <div class="layui-input-block">
                        <button class="layui-btn layui-btn-sm" lay-submit lay-filter="*"><i class="iconfont icon-chaxun"></i>Search</button>
                    </div>
                </div>
            </div>

        </div>
    </div>
</form>
<div class="table-body">
    <table id="balanceTable" lay-filter="balanceTable"></table>
</div>
<script>
    layui.use(['form', 'laydate', 'table',], function () {
        var laydate = layui.laydate,
            form = layui.form,
            table = layui.table; //表格
        //时间插件
        laydate.render({
            elem: '#datetime',
            range: '_',
            format: 'yyyy-MM-dd'
        });
        var tableIn = table.render({
            elem: '#balanceTable',
            height: 'full-99',
            cellMinWidth: '80',
            totalRow: true,
            method: 'post',
            url: "{:url('Cards/tranForceButton')}",
            id: 'balanceTable',
            //where:{tran_token : $('#tran_token').val()},
            toolbar: '#toolbar', //开启头部工具栏，并为其绑定左侧模板
            defaultToolbar: ['filter', 'exports'],
            cols: [[
                { type: 'numbers'},
                { field: 'username',  align: 'left', title: '会员',width: 180},
                { field: 'card_num', title: '卡号',width: 180,align:"left",totalRowText:'Total：', templet: function (d) {
                        const card_num = d.card_num;
                        var html = '<a style="color: #0e8df3;" ' +
                            'href="' + "{:url('cards/cardLog')}?card_num=" + card_num + '">' + card_num + '</a>';
                        return html;
                    }
                },
                { field: 'card_status', title: '卡状态', width:150 ,
                    templet:function (d) {
                        const status=   d.card_status;
                        var   html  =   '';
                        switch (status) {
                            case 1:
                                html = "<span style='color: green'>ACTIVE</span>";
                                break;
                            case 2:
                                html = "<span style='color: #6c757d'>SUSPENDED</span>";
                                break;
                            case 3:
                                html = "<span style='color: red'>CLOSED</span>";
                                break;
                            case 4:
                                html = "<span style='color: red'>Fraud</span>";
                                break;
                        }
                        return html;
                    }
                },//toolbar: '#status'},
                { field: 'amount',  align: 'right', title: '消费金额($)',width: 120,
                    style:'color:#FF5722;font-weight:bold',totalRow: true},
                { field: 'availableBalance',  align: 'right', title: '卡余额($)',width: 120,
                    style:'color:#FF5722;font-weight:bold',totalRow: true},
                { field: 'ctime', align: 'center', title: '交易时间' ,width: 170},
                { field: 'option', title: '备注', templet: function (d) {
                        var html = '<a class="layui-btn layui-btn-xs editDesc" data-id="' + d.id + '">备注</a>';
                        return html;
                    }, align: 'center',width: 70
                },
                { field: 'desc', align: 'left', title: 'Remark',width: 200},
                { field: 'shopping', align: 'left', title: 'shopping',width: 200},
                { field: 'tran_token', align: 'center', title: 'tran_token',width: 220},
            ]],
            page: true,
            limit: 20,
            limits: [20, 50, 100 ,500 ,1000],
        });
        form.on('submit(*)', function (data) {
            layui.table.reload('balanceTable', {
                where: data.field
                , page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        $(document).on('click', '.editDesc', function () {
            var id = $(this).attr('data-id');
            JsGet("{:url('editDesc')}?fz_id="+id, function(e){
                if(e.status == 1){
                    layer.open({
                        type: 1,
                        title: '强制消费备注',
                        area: ['550px', '300px'], //宽高
                        content: e.datas,
                        btn:['Confirm','Close'],
                        yes:function (index,layero) {
                            var thedata = $('.operationForm').serialize();
                            JsPost('{:url("editDesc")}', thedata,function (re) {
                                if(re.code >0){
                                    layer.msg(re.msg , {icon:1,time:1500});
                                    layer.close(index);
                                    tableIn.reload({
                                        page:{
                                            curr :1
                                        }
                                    });
                                }else{
                                    layer.msg(re.msg, {icon:2,time:1500});
                                }
                            });
                        }
                    });
                }else{
                    layer.msg(e.msg);
                }
            });
        });
    });
</script>